﻿@model IEnumerable<SIG.DAL.Dapper.Model.MenuCategory>
@{
    ViewBag.Title = EntityNames.Menu;
    ViewBag.PageTitle = ViewBag.Title + "_组件";
}


<div class="panel panel-default">
    <div class="panel-heading">
      
            <div class="pull-right">
                @Ajax.RawActionLink("<i class='fa fa-plus fa-fw'></i>" + string.Format("添加{0}", EntityNames.MenuCategory),
                        "AddCategory", "FrontMenu",
                        new { },
                        new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "edit-container", OnComplete = "onAjaxComplete", OnSuccess = "OnSuccessLink" },
                        new { @class = "btn btn-primary" })
            </div>

            @EntityNames.MenuCategory
      
    </div>
    <div class="panel-body">
        <div class="row" id="categoryList">
           @Html.Partial("_CategoryList",Model)
        </div>
    </div>
</div>



<div id="edit-container">
</div>

<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>

@section footer {
@Scripts.Render("~/bundles/jqueryvalWithBootstrap")

        <script>
            function OnSuccessLink(data) {
                Common.ShowBox(data.Status, data.Message, "操作")
            }

            function onAjaxBegin() {
                //  $("#divLoading").removeClass("divhide").addClass("divShow");
            }

            function onAjaxComplete() {
                $('#ModalMenuForm').modal();
            }

            function onBeginSave() {
                $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin")
            }
            function onCompleteSave() {
                $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save")
            }


            function onSuccess(data) {
                var title = '@ViewBag.PageTitle';
                Common.ShowBoxWithFuncBack(data, title, submitSuccess);
            }

            function submitSuccess(id, htmlData) {
                $('#ModalMenuForm').modal('hide');
                $("#menu" + id).html(htmlData);
            }


            function updateSuccess(data) {
                 var title = '@ViewBag.PageTitle';
                Common.ShowBoxWithFuncBack(data, title, submitCategorySuccess);
            }

            function submitCategorySuccess(id, htmlData) {
                $('#ModalMenuForm').modal('hide');                
                $("#categoryList").html(htmlData);              

            }

            $(function () {



                //展开折叠菜单
                $(document).on("click", '.expmenu', function (e) {
              //  $(".expmenu").on("click", function (e) {
                    e.preventDefault();

                    if ($(this).hasClass("expandmenu")) {
                        $(this).children("span").removeClass("glyphicon-minus-sign").addClass("glyphicon-plus-sign");
                    } else {
                        $(this).children("span").removeClass("glyphicon-plus-sign").addClass("glyphicon-minus-sign");
                    }

                    $(this).toggleClass("expandmenu")
                    $(this).closest("li").children("ul.menuTree").toggleClass("hidden");

                    var url = $(this).attr("data-url");
                    Common.SingleAction(url, "", false);

                });


                //delete
                $(document).on("click", '.delete-item', function (e) {
                    e.preventDefault();

                    var url = $(this).attr('data-url');
                    var that = $(this);
                    bootbox.setLocale("zh_CN");
                    bootbox.confirm("你确定要删除此项吗？", function (result) {
                        if (result) {
                            /*DELETE*/
                            var title = "@ViewBag.Title";
                            Common.DeleteItem(url, title, that);
                        }
                    });

                });

                //移动数据
                $(document).on("click", '.menuRemove', function (e) {
                    e.preventDefault();
                    var url = $(this).attr('href');
                    //      var confireMes = $(this).attr('data-confirm');
                    var menu = "#menu" + $(this).attr('data-categoryid');
                    var that = $(this);

                    bootbox.setLocale("zh_CN");

                    bootbox.confirm("是否确定删除该项？", function (result) {
                        if (result) {
                            $.post(url, $("#anti-form").serialize(), function (data) {

                                if (data.Status === 1) {
                                    toastr.error(data.Message, '@ViewBag.Title');
                                } else {
                                    toastr.success("已成功删除此项", '@ViewBag.Title');

                                    setTimeout(function () {
                                        location.reload();
                                    }, 1000);
                                }

                            });
                        }
                    });
                });


                //排序向上移动
                $(document).on("click", ".moveMenu", function (e) {
                    var url = $(this).attr('href');
                    var categoryId = $(this).attr('data-categoryid');
                    var that = $(this);
                    var title = "排序";
                    e.preventDefault();

                    Common.SingleActionWithFuncBack(url, title, categoryId, resetSortSuccess);

                    @*$.post(url, $("#anti-form").serialize(), function (data) {

                        switch (data.Status) {
                            case 2:
                                toastr.error(data.Message, '@ViewBag.Title');
                                break;
                            case 3:
                                toastr.info(data.Message, '@ViewBag.Title');
                                break;
                            case 1:
                                toastr.success("已成功排位菜单", '@ViewBag.Title');
                                setTimeout(function () {
                                    location.reload();
                                }, 1000);
                        }
                    });*@
                });

                //激活
                $('.active-item').click(function (e) {
                    e.preventDefault();
                    var url = $(this).attr('data-url'), title = $(this).attr('data-action'), that = $(this);

                    Common.SingleAction(url, title, true);

                });


                $('.btn-refresh').click(function (e) {
                    e.preventDefault();
                    var url = $(this).attr('data-url'), title = '重排序列', that = $(this).attr("data-id");
                    Common.SingleActionWithFuncBack(url, title, that, resetSortSuccess);
                    //(url, title, that, func)
                });



   

            });

            function resetSortSuccess(id,htmlData) {
                $("#menu" + id).html(htmlData);
            }
        </script>

    }
